package com.yuan.mint.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.yuan.mint.BaseApp;
import com.yuan.mint.R;
import com.yuan.mint.fragment.ExerciseFragment;
import com.yuan.mint.fragment.MyFragment;
import com.yuan.mint.fragment.NearbyFragment;
import com.yuan.mint.fragment.RecommendFragment;
import com.yuan.mint.utils.AppManager;
import com.yuan.mint.utils.FragmentTabUtils;

import java.util.ArrayList;

public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener {
    private long time;
    private ArrayList<Fragment> fragments = new ArrayList<Fragment>();
    private RadioGroup rgs;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        rgs = (RadioGroup) findViewById(R.id.main_rgs);
        fragments.add(new ExerciseFragment());
        fragments.add(new RecommendFragment());
        fragments.add(new NearbyFragment());
        fragments.add(new MyFragment());

        new FragmentTabUtils(this, getSupportFragmentManager(), fragments, R.id.main_fragment_container, rgs, this);

    }

    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - time > 1000) {
            time = currentTime;
            Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
        } else {
            AppManager.getInstance().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BaseApp.getInstance().unegisterNetworkStateReceiver();
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {
    }
}
